package edu.washington.ling.syntric.io;

import java.util.Set;
import java.io.IOException;

import edu.washington.ling.syntric.struct.error.InvalidValueException;


public abstract class TreeFileReader {
	private String path;
	private String layer;
	
	public TreeFileReader(String path, String layer) throws IOException {
		this.path = path;
		this.layer = layer;
	}
	public static TreeFileReader newReader(String path, String format, String layer) throws IOException, InvalidValueException {
		TreeFileReader tfr;
		if (format.equals("flat"))
			tfr = new TreeFileReaderFlat(path, layer);
		else if (format.equals("flat-multiline"))
			tfr = new TreeFileReaderFlatMultiline(path, layer);
		else if (format.equals("dir"))
			tfr = new TreeFileReaderDir(path, layer);
		else if (format.equals("sgml"))
			tfr = new TreeFileReaderSGML(path, layer);
		else {
			String[] possibleFormats = {"flat", "flat-multiline", "dir", "sgml"};
			throw new InvalidValueException("Specified tree format unknown.", format, possibleFormats);
		}
		return tfr;
	}
	public String getPath() {
		return path;
	}
	public String getLayer() {
		return layer;
	}
	public abstract int numTrees();
	public abstract Set<String> getIDs();
	//TODO: Convert these methods so that they no longer are reading files (tree reps are pre-cached) thus no longer need to throw IOException
	public abstract TreeRepresentation readNextTreeRep() throws IOException;
	public abstract boolean hasTreeRepWithID(String id);
	public abstract TreeRepresentation readTreeRepWithID(String id) throws IOException;
}
